<html>
<head><meta charset="utf-8"><title>Elevated priviliges for #[test_util] · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html">Elevated priviliges for #[test_util]</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205002904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Elevated%20priviliges%20for%20%23%5Btest_util%5D/near/205002904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wodann <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html#205002904">(Jul 25 2020 at 12:54)</a>:</h4>
<p>When writing unit tests using the <code>#[test]</code> proc_macro, you get access to private functions and member variables. When projects get larger it often makes sense to introduce utility functions for your tests that are shared between unit tests of different modules.</p>
<p>A problem with those test utils is that they lose the elevated privileges that would e.g. allow you to call a constructor with private fields. To solve this you could make the respective fields <code>pub(crate)</code> but that would leak beyond just a test use case.</p>
<p>I was going to propose a new proc_macro <code>#[test_util]</code> that would elevate privileges of such utility functions, but I am unsure where to start. Should I make a full-fledged RFC for this?</p>



<a name="205011005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Elevated%20priviliges%20for%20%23%5Btest_util%5D/near/205011005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html#205011005">(Jul 25 2020 at 16:37)</a>:</h4>
<p>I would be interested in this</p>



<a name="205011011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Elevated%20priviliges%20for%20%23%5Btest_util%5D/near/205011011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html#205011011">(Jul 25 2020 at 16:37)</a>:</h4>
<p>We have several things in <a href="http://docs.rs">docs.rs</a> that are public only for testing</p>



<a name="205016918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Elevated%20priviliges%20for%20%23%5Btest_util%5D/near/205016918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html#205016918">(Jul 25 2020 at 18:56)</a>:</h4>
<p>bikeshed: <code>#[sudo_test]</code></p>



<a name="205016949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Elevated%20priviliges%20for%20%23%5Btest_util%5D/near/205016949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html#205016949">(Jul 25 2020 at 18:57)</a>:</h4>
<p><span class="user-mention" data-user-id="260109">@Wodann</span> moving past the joke, the best way to advance this idea is to put in a major change proposal here: <a href="https://github.com/rust-lang/lang-team/issues">https://github.com/rust-lang/lang-team/issues</a>.</p>



<a name="205016997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Elevated%20priviliges%20for%20%23%5Btest_util%5D/near/205016997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html#205016997">(Jul 25 2020 at 18:58)</a>:</h4>
<p>(because it's a new <em>attribute</em> it falls under the lang domain, not libs)</p>



<a name="205017575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Elevated%20priviliges%20for%20%23%5Btest_util%5D/near/205017575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html#205017575">(Jul 25 2020 at 19:12)</a>:</h4>
<p>bikeshed: <code>#[pub_test]</code></p>



<a name="205017577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Elevated%20priviliges%20for%20%23%5Btest_util%5D/near/205017577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html#205017577">(Jul 25 2020 at 19:12)</a>:</h4>
<p>but the naming doesn't matter too much for now I think</p>



<a name="205022199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Elevated%20priviliges%20for%20%23%5Btest_util%5D/near/205022199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wodann <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html#205022199">(Jul 25 2020 at 21:23)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="224471">@Lokathor</span></p>



<a name="205022671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Elevated%20priviliges%20for%20%23%5Btest_util%5D/near/205022671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wodann <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html#205022671">(Jul 25 2020 at 21:38)</a>:</h4>
<p>I created an MCP issue: <a href="https://github.com/rust-lang/lang-team/issues/38">https://github.com/rust-lang/lang-team/issues/38</a></p>



<a name="205025578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Elevated%20priviliges%20for%20%23%5Btest_util%5D/near/205025578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Elevated.20priviliges.20for.20.23.5Btest_util.5D.html#205025578">(Jul 25 2020 at 23:03)</a>:</h4>
<p>MCP stream: <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Elevated.20privileges.20for.20.23.5Btest_util.5D.20lang-team.2338">https://rust-lang.zulipchat.com/#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Elevated.20privileges.20for.20.23.5Btest_util.5D.20lang-team.2338</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>